﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using PloobsEngine.SceneControl;
using PloobsEngine.Cameras;
using PloobsEngine.Factories;
using PloobsEngine;
using PloobsEngine.Input;
using PloobsEngine.Commands;
using PloobsEngine.Modelo;
using PloobsEngine.Material;
using PloobsEngine.Physics;
using PloobsEngine.Physics.XJigLib;

namespace Etapa1.BindKey
{
    public class BindThrow 
    {
        IWorld _mundo;
        ICamera _camera;
        Manager man;
        bool deferred;
        EngineStuff engine;
        public BindThrow(IWorld mundo, ICamera ca, EngineStuff engine, bool isderred)
        {  
             man = engine.Manager;
             _mundo = mundo;
             this.engine = engine;
            
            InputPlaybleMouseBottom ip1 = new SimpleConcreteMouseBottomInputPlayable(StateKey.PRESS, EntityType.IOBJECT, MouseButtons.LeftButton, mousebuttonteste);
            BindMouseCommand mm = new BindMouseCommand(ip1, BindAction.ADD);
            CommandProcessor.getCommandProcessor().SendCommandSyncronous(mm, InputAdvanced.MyName);
            this.deferred = isderred;
            this._camera = ca;
            _mundo = mundo;
       
        }
        public void mousebuttonteste(MouseState ms)
        {
            IObject physObj = SpawnPrimitive(_camera.Position, Matrix.CreateRotationX(0.5f));            
            physObj.PhysicObject.Velocity = (_camera.Target - _camera.Position) *100.0f;
            _mundo.AddObject(physObj);
      
        }
        Random random = new Random();
        private IObject SpawnPrimitive(Vector3 pos, Matrix ori)
        {
            //String lib;
            //    lib = ShaderLib.NONE;
            //    ///Criando um Objeto utilizando Shader
            //    SimpleShadedObjectRequest sor2 = new SimpleShadedObjectRequest(@"..\\Content\\Model\\Dsphere", PhysicObjectTypes.SPHEREOBJECT, pos, true, lib);
            //    IObject objx = man.getObject(sor2) as IObject;
            //    return objx;

            SimpleModel sm2 = new SimpleModel("..\\Content\\Model\\block", "..\\Content\\Textures\\white");
            sm2.LoadModelo();
            //ShaderLib s = new ShaderLib(engine);
            //IMaterial mat2 = new Material(s.getMaterial(ShaderLib.METAL));
            //IMaterial mat2 = new XnaMaterial(engine);
            //IPhysicObject pi2 = new SphereObject(sm2, pos, ori, 2);
            NormalDeferred nd = new NormalDeferred();
            NormalDeferredFakeShadowParcial s = new NormalDeferredFakeShadowParcial();
            s.ShadownAlpha = 0.5f;
            nd.PartialShader = s;
            nd.Initialize();
            IMaterial m = new Material(nd);
            IPhysicObject pi2 = new BoxObject(new Vector3(1), pos, Matrix.Identity, Vector3.One * 2);
            pi2.isMotionLess = false;
            return new SimpleObject(m, pi2, sm2);
            
        }


    }
}
